/*
 * DotWriter.cpp
 *
 *  Created on: 19/11/2013
 *      Author: asc
 */

#include "DotWriter.h"

namespace DotWriter
{

	ostream& operator<<(ostream& os, const DotWriter x)
	{
		os << header;
		int i=0;
		vector<Nodo> tmp(x.getGraph());
		map<string,int> relations;
		string rels="";

		for(vector<Nodo>::reverse_iterator it=tmp.rbegin(); it!=tmp.rend(); it++)
		{
			relations[it->revision]=i;
			os << "\"" << i << "\"" << typeNode << it->revision << "|" << it->timestamp << "\\l" << it->author << "|" << it->files;
			os << "}\"];" << endl;
			if(it->antecesor != "")
			{
				string str = it->antecesor;
				vector<std::string> tokens;

				split(tokens, str, is_any_of(" "));

				for(auto& s: tokens)
					os << '"' <<  relations[s] << '"' << "->" << '"' << i << '"' << relation << endl;
			}
			i++;
		}
		os << "}";
		relations.clear();
		return(os);
	}

	DotWriter::DotWriter()
	{
		// TODO Auto-generated constructor stub

	}

	DotWriter::~DotWriter()
	{
		graph.clear();
	}

	void DotWriter::addNodo(Nodo x)
	{
		graph.push_back(x);
	}

	vector<Nodo> DotWriter::getGraph()const
	{
		return(graph);
	}

} /* namespace DotWriter */
